from configparser import ConfigParser
from base import config
from base.config import file_dir

section = 'pytest'
fp = file_dir.pytest_ini

class OperateConfig:

    def __init__(self):
        self.config = ConfigParser()
        self.config.read(fp)
        params = dict(testpaths=config.testpaths,
                      python_files=config.python_files,
                      python_classes=config.python_classes,
                      python_functions=config.python_functions)
        tuple(map(self.write, params.items()))

    def read(self, key):
        data = self.config.get(section, str(key))
        return data

    def set(self, key, new_value):
        self.config.set(section, key, new_value)

    def write(self, params):
        key, value = params
        self.set(key, value)
        with open(fp, 'w') as fi:
            self.config.write(fi)



if __name__ == '__main__':
    pass
    # a01 = op_config.dir_report
    # print(a01, type(a01))
    # op_config.write('test01', '666')
    # data = op_config.read('report')
    # print(data, type(data))
